#! /bin/sh

#
# first of all generate a list of functions
#
rm -f iup.fu iup.err
for a in `( cd ../iup/include ; ls *.h )` ; do
  ./fugen $a -- -I../iup/include >>iup.fu 2>>iup.err
done

#
# now bong this list against the libraries
#
iuplibs=../iup/lib
rm -f iup.fu2
for a in $iuplibs/*.so* ; do
  echo lazylink `basename $a` >>iup.fu2
  ./bong $a <iup.fu 2>/dev/null >>iup.fu2
done
echo lazy off >>iup.fu2

cat <<EOT >iup.interface
|
| HelFORTH interface to IUP portable user interface
|
context Iup
{~ Iup
EOT

perl <iup.fu2 >>iup.interface -e '
#
# cleanups
#
  my $last = "";
  while (<>) {
  	my ($w, $x, $y);
  	while (/^\|\n/) {
  		$w = $_;
  		$x = <>;
  		$y = <>;
  		$_ = <>;
  		if (/^((\|)|(lazy))/) {
  			$w = $x = $y = "";
  		}
  	}
	/^lazy/ and $last = "";
  	print $last, $w, $x, $y;
  	if (/^lazy/) {
  		$last = "\n\n$_";
  	} else {
  		print $_;
  		$last = "";
  	}
  }
  print $last; # lazy off
'
echo "~}" >>iup.interface

rm -f iup.fu iup.fu2
# keep iup.err
